<?php


namespace app\pxs\controller;


use app\common\Common;
use app\pxs\service\JwtService;
use app\sys\service\GateCli;
use think\facade\Cache;
use think\facade\Validate;
use think\Request;

class WsLogin extends Common
{
    // 链接绑定
    public function wsBindCry(Request $request){
        $data = $request->param();
        $validate = Validate::make([
            "client_id|ws链接id" => "require",
        ]);
        if (!$validate->check($data)) {
            return failedJson($validate->getError());
        }
        $jwt = $request->_user;
        $data["user_no"] = $jwt["no"];

        // 会员判断
        $isMen = 0;
        $user = \app\admin\model\User::where("no", $data["user_no"])->find();
        if($user){
            if($user["mobile"])$isMen = 1;
        }
        if(isset($jwt["mobile"]))$isMen = 1;


        $cli = new GateCli();
        $st = $cli->wsUserBind($data["client_id"],$data["user_no"],$user["id"],$isMen,$jwt["device_id"]);
        if($st){
            return failedJson($st."绑定失败");
        }
        return successJson("success","绑定成功");
    }
}